'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:UserdefinedChoosepersonCtrl
 * @description
 * # UserdefinedChoosepersonCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('UserdefinedChoosepersonCtrl', function(openApi, DataByPage, Util) {
        var vm = this
        this.peopleArr = []
        this.confirm = function() {
            if (this.peopleArr.length < 1) {
                Util.Toast("请选择审核人员")
                return;
            }
            var SPperson = Util.getLocalInfo("SPperson");
            this.peopleArr = Util.mergeArr(this.peopleArr, SPperson, "userId")
            Util.saveLocalInfo("SPperson", this.peopleArr);
            Util.goBack();
        }
        this.selectpeople = function(item, index) {
            // console.log(this.peopleArr)
            if (item.selected) {
                addPerson(item)
            } else {
                rmPerson(item);
            }
        }
        var addPerson = function(per) {
            vm.peopleArr.push(per)
            per.indexId = vm.peopleArr.length
        };
        var rmPerson = function(per) {
            var curIndex
            vm.peopleArr.filter(function(item, index) {
                if (item.userId == per.userId) {
                    curIndex = index
                }
            })
            vm.peopleArr.splice(curIndex, 1);
        };
        this.initData = function() {
            vm.peoplelist = new DataByPage(openApi.getPageListByAccount, {
                limit: 25
            });
        }
        this.initData();
    });
